// Copyright (C) 2018 Chen XiaWen sup9@qq.com
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <stdio.h>
#include <stdlib.h>
#include <QDebug>
#include <QTextCodec>
#include <fstream>
#include <iostream>
#include <memory>
#include "tool/request.h"
#include "tool/request_creator.h"

int main(int argc, char const *argv[]) {
  const char *url = "http://www.baidu.com";
  char *now = setlocale(LC_ALL, "zh_CN.utf8");
  std::cout << now << std::endl;
  // const char *url = "http://2018.ip138.com/ic.asp";
  RequestCreator::instance()->HttpGet(url);
  QString str = QTextCodec::codecForName("GB2312")->toUnicode(RequestCreator::instance()->get_resource().c_str());
  // qDebug() << str.toStdString().c_str();
  qDebug() << RequestCreator::instance()->get_resource().c_str();
  qDebug() << QString(u8"这是我");
  qDebug() << QString("这是我");
  std::ofstream myfile;
  QString file_name("curl_output");
  file_name = file_name + "spec_id_" + ".txt";
  myfile.open(file_name.toStdString().c_str());
  myfile.write(RequestCreator::instance()->get_resource().c_str(), RequestCreator::instance()->get_resource().length());
  myfile.close();
  return 0;
}
